require 'socket'
require 'thread'
require 'csputil'
class STUNTServer
  def initialize(host,port)
    @server = TCPServer.new(host, port)
    @server.listen(5)
  end
  def run
    Thread.new do
      serve
    end
  end
  def getSocketAddress
    @server.addr
  end
  def serve
    while(socket=@server.accept)
      obj=Util.socketAddress( socket.peeraddr)
      socket.send(Util.getBytes(obj),0)
      socket.close
    end
  end
end
if $0==__FILE__ then
#  Test.socketAddress
  s=STUNTServer.new("localhost",5150)
  #s.serve
  a=Java::JavaArray.new
  a.push(Util.socketAddress(s.getSocketAddress));
  a.push(Util.socketAddress(s.getSocketAddress));
  p Util.getBytes(a)
  p s.getSocketAddress
end